package com.gis.bigdata.spark.core.acc

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author LnnuUser
 * @create 2021-09-01-上午11:05
 */
object Spark01_Acc {

  def main(args: Array[String]): Unit = {

    val sparkConf: SparkConf = new SparkConf().setMaster("local").setAppName("Acc")
    val sc: SparkContext = new SparkContext(sparkConf)

    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))

//    val i: Int = rdd.reduce(_ + _)
//    println(i)

    var sum = 0
    rdd.foreach(
      num => {
        sum += num
      }
    )

    println(sum)

    sc.stop()
  }

}
